package Leetcode.lc024;

import Leetcode.tools.ListNode;

import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;

/***
 * 链表两两交换
 */
public class Sloution {
    public ListNode swapPairs(ListNode head) {
        ListNode node = new ListNode(0, head);
        ListNode first=null,second=null;
        ListNode cur=node;
        while(cur.next!=null && cur.next.next!=null){
            first=cur.next;
            second=cur.next.next;
            cur.next=second;
            first.next=second.next;
            second.next=first;
            cur=cur.next.next;
        }
        return node.next;
    }

    public static void main(String[] args) {
        Sloution sloution = new Sloution();
        int[] ints = {1, 2, 3, 4};
        ListNode head = new ListNode();
        ListNode node = head.listBuilder(ints);
        ListNode node1 = sloution.swapPairs(node);
        head.printAll(node1);
    }
}
